#include "EquationSolver.h"
#include <limits>

double pi = acos(-1);
double eps = numeric_limits<double>::epsilon();

class Func1 : public Function{
public:
  double operator()(double x){
    return 1/x-tan(x);
  }
  double diff(double x){
    return 0;
  }
};

Func1 func1;

double test1(){
  Bisection solver(func1, 0, pi/2, eps, eps, 100);
  double result = solver.solve();
  return result;
}
//1/x-2^x
class Func2 : public Function{
public:
  double operator()(double x){
    return (1/x-pow(2,x));
  }
};

Func2 func2;

double test2(){
  Bisection solver(func2, 0, 1, eps, eps, 100);
  double result = solver.solve();
  return result;
}
//
class Func3 : public Function{
public:
  double operator()(double x){
    return (pow(0.5,x)+exp(x)+2*cos(x)-6);
  }
};

Func3 func3;

double test3(){
  Bisection solver(func3, 1, 3, eps, eps, 100);
  double result = solver.solve();
  return result;
}

class Func4 : public Function{
public:
  double operator()(double x){
    return (pow(x,3)+4*pow(x,2)+3*x+5)/(2*pow(x,3)-9*pow(x,2)+18*x-2);
  }
};

Func4 func4;

double test4(){
  Bisection solver(func4, 0, 4, eps, eps, 100);
  double result = solver.solve();
  return result;
}

int main(){
  cout << "The root of function 1/x-tan(x) is " << test1() << endl;
  cout << "The root of function 1/x-2^x is " << test2() << endl;
  cout << "The root of function 2^{-x}+exp{x}+2cos(x)-6 is " << test3() << endl;
  cout << "The root of function (x^3+4x^2+3x+5)/(2x^3-9x^2+18x-2) is " << test4() << endl;
  return 0;
}
